from game_helpers import Board

class BoatPlaceUtil(object):
    """ Boat Place Utility Class
        Implements functions for each player to use to check validity of boat placements. 
        This class only contains information relevant to the current round, and will be reset once
        either player has won."""
    def __init__(self):
        self.board = Board()
    
    def is_valid_placement(self, length, x_coord, y_coord, orientation):
        """ Return's True and add's the boat to your local. 
            Else it will return False."""
        try:
            self.board.place_boat()
            return True
        except:
            return False
    
    def get_boats_added(self):
        """ Returns a list of the length of the boats already added. """
        length_list = []
        for boat in self.board._boats_on_board():
            if boat:
                length_list.append( len(boat) )
        
        return length_list
    
    
    def get_coords_from_util(self):
        coords = []
        for boat in self.board._boats_on_board():
            if boat:
                boat_params = []
                boat_params.append(boat.length)
                boat_params.append(boat.origin[0])
                boat_params.append(boat.origin[1])
                boat_params.append(boat.orientation)
                coords.append(boat_params)
        return coords
    
    def all_boats_placed(self):
        return self.board.abs()
        
        
            
        